//
//  B_GoodsDetailHeaderView.m
//  DreamOf
//
//  Created by 薛小刚 on 2018/9/24.
//  Copyright © 2018年 薛小刚. All rights reserved.
//

#import "B_GoodsDetailHeaderView.h"

@interface B_GoodsDetailHeaderView()<SDCycleScrollViewDelegate>

@property (nonatomic, strong) SDCycleScrollView * cycleScrollView;

@property (nonatomic, strong) UILabel * pageLabel;


@end

@implementation B_GoodsDetailHeaderView
+ (instancetype)initB_GoodsDetailHeaderView {
    B_GoodsDetailHeaderView * view = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil].lastObject;
    [view setView];
    
    return view;
}


- (void) setView {
    _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:self.B_view.bounds delegate:self placeholderImage:[UIImage imageNamed:@"image_Failed"]];
    _cycleScrollView.backgroundColor = [UIColor whiteColor];
    _cycleScrollView.delegate       = self;
    _cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
    /// 设置滚动时间
    //    _cycleScrollView.autoScrollTimeInterval = 8.0f;
    _cycleScrollView.autoScroll = NO;
    [self.B_view addSubview:_cycleScrollView];
    
    [_cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.B_view);
    }];
    
    _pageLabel = [[UILabel alloc] init];
    [self.B_view addSubview:_pageLabel];
    [_pageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.B_view.mas_right).offset(-16);
        make.bottom.equalTo(self.B_view.mas_bottom).offset(-20);
        make.height.equalTo(@(30));
        make.width.equalTo(@(50));
        
    }];
    WeakSelf(weSelf, self);
    _cycleScrollView.itemDidScrollOperationBlock = ^(NSInteger currentIndex) {
        weSelf.pageLabel.text = [NSString stringWithFormat:@"%ld/%ld", currentIndex + 1, weSelf.array.count];
    };
    _pageLabel.textColor = [UIColor whiteColor];
    _pageLabel.font = [UIFont systemFontOfSize:14];
    _pageLabel.textAlignment = NSTextAlignmentCenter;
    _pageLabel.layer.masksToBounds = YES;
    _pageLabel.layer.cornerRadius = 15;
    _pageLabel.backgroundColor = [UIColor color_text_deep_gray];
}

- (void) setArray:(NSArray *)array {
    _array = array;
    self.pageLabel.text = [NSString stringWithFormat:@"1/%ld", array.count];
    _cycleScrollView.imageURLStringsGroup = array;
}

#pragma mark -> 代理方法
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
//    if (self.topicHeaderAction) {
//        self.topicHeaderAction(index, NO);
//    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
